package com.formiaomiao.demain.controller;

import com.formiaomiao.demain.model.CommentBean;
import com.formiaomiao.demain.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

@Controller
@RequestMapping(value = "/comment")
public class CommentController {
    @Autowired
    CommentService commentService;

    /**
     * 评论
     *
     * @param topicid
     * @param content
     * @param fromuid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/insertcomment")
    private Object InsertComment(@RequestParam(name = "topicid", required = false) String topicid,
                                 @RequestParam(name = "content", required = false) String content,
                                 @RequestParam(name = "fromuid", required = false) Integer fromuid) {
        CommentBean commentBean = new CommentBean();
        commentBean.setComid(UUID.randomUUID().toString());
        commentBean.setContent(content);
        commentBean.setTopicid(topicid);
        commentBean.setFromuid(fromuid);
        commentBean.setCreateDate(String.valueOf(System.currentTimeMillis()));
        return commentService.InsertComment(commentBean);
    }

    /**
     * 删除评论
     *
     * @param comid
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/deletecomment")
    private Object DeleteComment(@RequestParam(name = "comid", required = false) String comid) {
        CommentBean commentBean = new CommentBean();
        commentBean.setComid(comid);
        return commentService.DeleteComment(commentBean);
    }

    /**
     * 查询评论
     *
     * @param topicid
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectcomment")
    private Object SelectComment(@RequestParam(name = "topicid", required = false) String topicid,
                                 @RequestParam(name = "pageNum", required = false) Integer pageNum,
                                 @RequestParam(name = "pageSize", required = false) Integer pageSize) {
        return commentService.SelectComment(topicid, pageNum, pageSize);
    }
}
